package de.gbeine.java.depview.beans.converter;

import java.util.HashMap;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import de.gbeine.java.depview.model.Class;

/**
 *
 * @author gbeine
 */
@Slf4j
public final class ClassFactory {

    private static final Map<String, Class> CLASSES = new HashMap<String, Class>();

    private ClassFactory() {
        super();
    }

    public static Class createClass(final String name) {
        Class  ce;
        if (ClassFactory.CLASSES.containsKey(name)) {
            if (ClassFactory.log.isDebugEnabled()) {
                ClassFactory.log.debug("ClassElement " + name + " already exists.");
            }
            ce = ClassFactory.CLASSES.get(name);
        } else {
            if (ClassFactory.log.isDebugEnabled()) {
                ClassFactory.log.debug("Creating new ClassElement: " + name);
            }
            ce = new Class(name);
            ClassFactory.CLASSES.put(name, ce);
        }
        return ce;
    }
}
